package com.scsj.supermarket.presenter;

import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.orhanobut.logger.Logger;
import com.scsj.supermarket.base.HomeClassifyBase;
import com.scsj.supermarket.bean.HomeClassifyBean;
import com.scsj.supermarket.model.HomeClassifyModel;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 分类页面（首页第二个页面）
 */

public class HomeClassfiyPresenter extends BasePresenter implements HomeClassifyBase.IPresenter {

    private HomeClassifyBase.IView mView;
    private HomeClassifyBase.IModel mModel;

    public HomeClassfiyPresenter(HomeClassifyBase.IView mView) {
        this.mView = mView;
        mModel = new HomeClassifyModel();
    }

    @Override
    public void deliverData() {

        addSubscription(mModel.getData( new ResponseCallback<HomeClassifyBean>() {
            @Override
            public void onSuccess(HomeClassifyBean result) {

                if (result.getStatusCode() == 200) {

                    mView.showSuccessMsg("获取成功", result);
                    Logger.e("获取成功" + result.toString());
                } else {
                    mView.showErrorMsg(result.getMsg());
                    Logger.e("未成功" + result.toString());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("失败", msg + "");
            }
        }));

    }
}
